package gestures;

import java.awt.geom.Point2D;
import java.util.Calendar;

/**
 * Basic gesture structure
 * 
 * @author PDAY (Patrick B. Day, The MITRE Corporation)
 * 
 */
public abstract class Gesture {

	private Gesture prevGesture;
	private Calendar gestureTime;
	private Point2D.Float gestureCenter;
	private Point2D.Float[] gestureCoords;
	private int index;
	private int id;

	/**
	 * Create an instance of this gesture
	 * 
	 * @param time
	 *            Time this gesture occurred in the application
	 * @param coordinates
	 *            Coordinates this gesture was captured at
	 */
	public Gesture(int id, Calendar time, Point2D.Float[] coordinates) {
		this(id, 0, time, coordinates);
	}

	/**
	 * Create an instance of this gesture
	 * 
	 * @param index
	 *            Priority index for this gesture if multiple gestures occurred
	 *            in the same bounds
	 * @param time
	 *            Time this gesture occurred in the application
	 * @param coordinates
	 *            Coordinates this gesture was captured at
	 */
	public Gesture(int id, int index, Calendar time, Point2D.Float[] coordinates) {
		this(id, index, null, time, coordinates);
	}

	/**
	 * Create an instance of this gesture
	 * 
	 * @param prevGesture
	 *            A previous gesture associated with this current gesture (i.e.
	 *            a gesture starting object)
	 * @param time
	 *            Time this gesture occurred in the application
	 * @param coordinates
	 *            Coordinates this gesture was captured at
	 */
	public Gesture(int id, Gesture prevGesture, Calendar time,
			Point2D.Float[] coordinates) {
		this(id, 0, prevGesture, time, coordinates);
	}

	/**
	 * Create an instance of this gesture
	 * 
	 * @param index
	 *            Priority index for this gesture if multiple gestures occurred
	 *            in the same bounds
	 * @param prevGesture
	 *            A previous gesture associated with this current gesture (i.e.
	 *            a gesture starting object)
	 * @param time
	 *            Time this gesture occurred in the application
	 * @param coordinates
	 *            Coordinates this gesture was captured at
	 */
	public Gesture(int id, int index, Gesture prevGesture, Calendar time,
			Point2D.Float[] coordinates) {
		this.id = id;
		this.index = index;
		this.prevGesture = prevGesture;
		this.gestureTime = time;
		this.gestureCoords = coordinates;
	}

	/**
	 * Get the unique ID of this gesture
	 * @return ID of this gesture
	 */
	public int getID() {
		return this.id;
	}
	
	/**
	 * Set the unique ID of this gesture
	 * @param value ID to set as
	 */
	public void setID(int value) {
		this.id = value;
	}
	
	/**
	 * Get the index of this gesture on the display. Used to determine gesture
	 * priority when multiple gesture overlay in the same area
	 * 
	 * @return Index of this gesture
	 */
	public int getIndex() {
		return this.index;
	}

	/**
	 * Set the index of this gesture on the display. Used to determine gesture
	 * priority when multiple gesture overlay in the same area
	 * 
	 * @param value
	 *            New index for this gesture
	 */
	public void setIndex(int value) {
		this.index = value;
	}

	/**
	 * Get the time that this gesture event occurred
	 * 
	 * @return Time that this gesture event occurred
	 */
	public Calendar getGestureTime() {
		return this.gestureTime;
	}

	/**
	 * Set the time that this gesture event occurred
	 * 
	 * @param value
	 *            Time that this gesture event occurred
	 */
	public void setGestureTime(Calendar value) {
		this.gestureTime = value;
	}

	public Point2D.Float getGestureCenter() {
		return this.gestureCenter;
	}
	public void setGestureCenter(Point2D.Float value){
		this.gestureCenter = value;
	}
	
	/**
	 * Get the location in the application that this gesture occurred
	 * 
	 * @return The location in the application that this gesture occurred
	 */
	public Point2D.Float[] getGestureCoords() {
		return this.gestureCoords;
	}

	/**
	 * Set the location in the application that this gesture occurred
	 * 
	 * @param value
	 *            The location in the application that this gesture occurred
	 */
	public void setGestureCoords(Point2D.Float[] value) {
		this.gestureCoords = value;
	}

	/**
	 * Get the previous gesture associated with this gesture motion
	 * 
	 * @return Previous gesture in the series
	 */
	public Gesture getPreviousGesture() {
		return this.prevGesture;
	}

	/**
	 * Set the previous gesture associated with this gesture motion
	 * 
	 * @param value
	 *            Previous gesture to associate with
	 */
	public void setPreviousGesture(Gesture value) {
		this.prevGesture = value;
	}

	/**
	 * Print out the appropriate gesture information. More information than
	 * desired in a toString()
	 * 
	 * @return List of gesture type, index, time, coordinates, and any previous
	 *         gestures associated with this gesture
	 */
	public String toDebug() {

		String retStr = "Gest type: " + this.getClass().toString() + "\n";
		retStr += "Index: " + this.index + "\n";
		retStr += "Time: " + this.gestureTime.getTime().toString() + "\n";
		retStr += "Coords: \n";
		for (int i = 0; i < this.gestureCoords.length; i++) {
			retStr += this.gestureCoords[i].toString() + "\n";
		}
		retStr += "Previous Gestures: \n";
		if (this.prevGesture != null)
			retStr += this.prevGesture.toDebug();
		else
			retStr += "none";

		return retStr;
	}

}
